package com.vancouver.knows.business.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.pangu.util.StringUtil;
import com.vancouver.knows.business.bean.EditUserInfo;
import com.vancouver.knows.business.bean.UserInfo;

/**
 * Created by Chris Li on 2016-07-22.
 */
public class EditUserProfileHandler extends ACheckableJsonParser {

    private EditUserInfo editUserInfo = null;

    @Override
    protected void parserContent(JSONObject content) throws Exception {

        editUserInfo = new EditUserInfo();

        String displayName = content.getString("display_name");
        if (!StringUtil.isEmptyString(displayName)) {
            editUserInfo.setDisplayName(displayName);
        }

        String registerType = content.getString("register_type");
        if (!StringUtil.isEmptyString(registerType)) {
            editUserInfo.setRegisterType(JSON.parseObject(registerType, UserInfo.RegisterType.class));
        }

        String userMeta = content.getString("user_meta");
        if (!StringUtil.isEmptyString(userMeta)) {
            editUserInfo.setUserMeta(JSON.parseObject(userMeta, UserInfo.UserMeta.class));
        }

        String cityList = content.getString("city_list");
        if (!StringUtil.isEmptyString(cityList)) {
            editUserInfo.setCityList(JSON.parseArray(cityList, String.class));
        }
    }

    public EditUserInfo getEditUserInfo() {
        return editUserInfo;
    }
}
